 package tools.packet;



import client.MapleCharacter;
import client.MapleClient;
import handling.channel.MapleGuildRanking;
import handling.opcode.GuildOpcode;
import handling.opcode.SendPacketOpcode;
import handling.world.WorldGuildService;
import handling.world.guild.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.output.MaplePacketLittleEndianWriter;

import java.util.Collection;
import java.util.List;























 public class GuildPacket
 {
/*  28 */   private static final Logger log = LogManager.getLogger(GuildPacket.class);




   public static byte[] guildInvite(int guildId, String guildName, String charName, int levelFrom, int jobFrom) {
/*  34 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/*  35 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  37 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/*  38 */     mplew.write(GuildOpcode.GuildRes_InviteGuild_Done.getValue());
/*  39 */     mplew.writeInt(guildId);
/*  40 */     mplew.writeMapleAsciiString(guildName);
/*  41 */     mplew.writeInt(levelFrom);
/*  42 */     mplew.writeMapleAsciiString(charName);
/*  43 */     mplew.writeInt(levelFrom);
/*  44 */     mplew.writeInt(jobFrom);
/*  45 */     mplew.writeInt(0);

/*  47 */     return mplew.getPacket();
   }





   public static byte[] showGuildInfo(MapleCharacter chr) {
/*  55 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/*  57 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/*  58 */     mplew.writeShort(GuildOpcode.GuildRes_LoadGuild_Done.getValue());

/*  60 */     if (chr == null || chr.getMGC() == null) {
/*  61 */       mplew.write(0);
/*  62 */       return mplew.getPacket();
     }
/*  64 */     MapleGuild guild = WorldGuildService.getInstance().getGuild(chr.getGuildId());
/*  65 */     if (guild == null) {
/*  66 */       mplew.write(0);
/*  67 */       return mplew.getPacket();
     }
/*  69 */     mplew.write(1);

/*  71 */     addGuildInfo(mplew, guild);

/*  73 */     addGuildExpInfo(mplew, guild);

/*  75 */     return mplew.getPacket();
   }





   public static byte[] showPlayerGuildInfo(MapleGuild guild) {
/*  83 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/*  84 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/*  85 */     mplew.write(GuildOpcode.GuildRes_FindGuild_Done.getValue());
/*  86 */     mplew.writeInt(guild.getId());
/*  87 */     addGuildInfo(mplew, guild);

/*  89 */     return mplew.getPacket();
   }

   private static void addGuildInfo(MaplePacketLittleEndianWriter mplew, MapleGuild guild) {
/*  93 */     mplew.writeInt(guild.getId());
/*  94 */     mplew.writeMapleAsciiString(guild.getName());

/*  96 */     for (int i = 1; i <= 5; i++) {
/*  97 */       mplew.writeMapleAsciiString(guild.getRankTitle(i));
     }

/* 100 */     guild.addMemberData(mplew);

/* 102 */     mplew.writeInt(guild.getCapacity());

/* 104 */     mplew.writeShort(guild.getLogoBG());
/* 105 */     mplew.write(guild.getLogoBGColor());
/* 106 */     mplew.writeShort(guild.getLogo());
/* 107 */     mplew.write(guild.getLogoColor());

/* 109 */     mplew.writeMapleAsciiString(guild.getNotice());

/* 111 */     mplew.writeInt(guild.getGP());
/* 112 */     mplew.writeInt(guild.getGP());

/* 114 */     mplew.writeInt((guild.getAllianceId() > 0) ? guild.getAllianceId() : 0);

/* 116 */     mplew.write(guild.getLevel());
/* 117 */     mplew.writeShort(0);
/* 118 */     mplew.writeInt(0);

/* 120 */     mplew.writeShort(guild.getSkills().size());
/* 121 */     for (MapleGuildSkill mapleGuildSkill : guild.getSkills()) {
/* 122 */       mplew.writeInt(mapleGuildSkill.skillID);
/* 123 */       mplew.writeShort(mapleGuildSkill.level);
/* 124 */       mplew.writeLong(PacketHelper.getTime(mapleGuildSkill.timestamp));
/* 125 */       mplew.writeMapleAsciiString(mapleGuildSkill.purchaser);
/* 126 */       mplew.writeMapleAsciiString(mapleGuildSkill.activator);
     }
/* 128 */     mplew.write(0);
   }

   private static void addGuildExpInfo(MaplePacketLittleEndianWriter mplew, MapleGuild guild) {
/* 132 */     int[] guildExp = guild.getGuildExp();
/* 133 */     mplew.writeInt(guildExp.length);
/* 134 */     for (int aGuildExp : guildExp) {
/* 135 */       mplew.writeInt(aGuildExp);
     }
   }




   public static byte[] createGuild(MapleGuild guild) {
/* 143 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 144 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 146 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 147 */     mplew.write(GuildOpcode.GuildRes_CreateNewGuild_Done.getValue());
/* 148 */     addGuildInfo(mplew, guild);

/* 150 */     return mplew.getPacket();
   }




   public static byte[] guildSkillPurchased(int guildId, int skillId, int level, long expiration, String purchase, String activate) {
/* 157 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 158 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 160 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 161 */     mplew.write(GuildOpcode.GuildRes_SetSkill_Done.getValue());
/* 162 */     mplew.writeInt(guildId);
/* 163 */     mplew.writeInt(skillId);
/* 164 */     mplew.writeShort(level);
/* 165 */     mplew.writeLong(PacketHelper.getTime(expiration));
/* 166 */     mplew.writeMapleAsciiString(purchase);
/* 167 */     mplew.writeMapleAsciiString(activate);

/* 169 */     return mplew.getPacket();
   }









   public static byte[] genericGuildMessage(byte code) {
/* 181 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 182 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 184 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 185 */     mplew.write(code);

/* 187 */     return mplew.getPacket();
   }





   public static byte[] newGuildMember(MapleGuildCharacter mgc, boolean isApply) {
/* 195 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 196 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 198 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 199 */     mplew.write(isApply ? GuildOpcode.GuildRes_JoinRequest_Done.getValue() : GuildOpcode.GuildRes_JoinGuild_Done.getValue());
/* 200 */     mplew.writeInt(mgc.getGuildId());
/* 201 */     mplew.writeInt(mgc.getId());
/* 202 */     mplew.writeAsciiString(mgc.getName(), 13);
/* 203 */     mplew.writeInt(mgc.getJobId());
/* 204 */     mplew.writeInt(mgc.getLevel());
/* 205 */     mplew.writeInt(mgc.getGuildRank());
/* 206 */     mplew.writeInt(mgc.isOnline() ? 1 : 0);
/* 207 */     mplew.writeInt(mgc.getAllianceRank());
/* 208 */     mplew.writeInt(mgc.getGuildContribution());
/* 209 */     mplew.writeInt(0);
/* 210 */     mplew.writeInt(0);
/* 211 */     mplew.writeLong(PacketHelper.getTime(-2L));

/* 213 */     return mplew.getPacket();
   }




   public static byte[] DenyGuildApply(int chrId) {
/* 220 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 221 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 223 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 224 */     mplew.write(GuildOpcode.GuildRes_JoinCancelRequest_Done.getValue());
/* 225 */     mplew.writeInt(chrId);

/* 227 */     return mplew.getPacket();
   }





   public static byte[] memberLeft(MapleGuildCharacter mgc, boolean isExpelled) {
/* 235 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 236 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 238 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 239 */     mplew.write(isExpelled ? GuildOpcode.GuildRes_KickGuild_Done.getValue() : GuildOpcode.GuildRes_WithdrawGuild_Done.getValue());
/* 240 */     mplew.writeInt(mgc.getGuildId());
/* 241 */     mplew.writeInt(mgc.getId());
/* 242 */     mplew.writeMapleAsciiString(mgc.getName());

/* 244 */     return mplew.getPacket();
   }





   public static byte[] guildNotice(int guildId, String notice) {
/* 252 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 253 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 255 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 256 */     mplew.write(GuildOpcode.GuildRes_SetNotice_Done.getValue());
/* 257 */     mplew.writeInt(guildId);
/* 258 */     mplew.writeMapleAsciiString(notice);

/* 260 */     return mplew.getPacket();
   }





   public static byte[] guildDisband(int guildId) {
/* 268 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 269 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 271 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 272 */     mplew.write(GuildOpcode.GuildRes_RemoveGuild_Done.getValue());
/* 273 */     mplew.writeInt(guildId);
/* 274 */     mplew.write(1);

/* 276 */     return mplew.getPacket();
   }





   public static byte[] denyGuildInvitation(String charname) {
/* 284 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 285 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 287 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 288 */     mplew.write(GuildOpcode.GuildRes_InviteGuild_Rejected.getValue());
/* 289 */     mplew.writeMapleAsciiString(charname);

/* 291 */     return mplew.getPacket();
   }





   public static byte[] guildCapacityChange(int guildId, int capacity) {
/* 299 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 300 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 302 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 303 */     mplew.write(GuildOpcode.GuildRes_IncMaxMemberNum_Done.getValue());
/* 304 */     mplew.writeInt(guildId);
/* 305 */     mplew.write(capacity);
/* 306 */     mplew.writeInt(0);

/* 308 */     return mplew.getPacket();
   }





   public static byte[] guildMemberLevelJobUpdate(MapleGuildCharacter mgc) {
/* 316 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 317 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 319 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 320 */     mplew.write(GuildOpcode.GuildRes_ChangeLevelOrJob.getValue());
/* 321 */     mplew.writeInt(mgc.getGuildId());
/* 322 */     mplew.writeInt(mgc.getId());
/* 323 */     mplew.writeInt(mgc.getLevel());
/* 324 */     mplew.writeInt(mgc.getJobId());

/* 326 */     return mplew.getPacket();
   }





   public static byte[] guildMemberOnline(int guildId, int chrId, boolean isOnline) {
/* 334 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 335 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 337 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 338 */     mplew.write(GuildOpcode.GuildRes_NotifyLoginOrLogout.getValue());
/* 339 */     mplew.writeInt(guildId);
/* 340 */     mplew.writeInt(chrId);
/* 341 */     mplew.write(isOnline ? 1 : 0);
/* 342 */     mplew.write(1);

/* 344 */     return mplew.getPacket();
   }





   public static byte[] rankTitleChange(int guildId, String[] ranks) {
/* 352 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 353 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 355 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 356 */     mplew.write(GuildOpcode.GuildRes_SetGradeName_Done.getValue());
/* 357 */     mplew.writeInt(guildId);
/* 358 */     for (String r : ranks) {
/* 359 */       mplew.writeMapleAsciiString(r);
     }
/* 361 */     mplew.writeInt(0);

/* 363 */     return mplew.getPacket();
   }





   public static byte[] changeRank(MapleGuildCharacter mgc) {
/* 371 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 372 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 374 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 375 */     mplew.write(GuildOpcode.GuildRes_SetMemberGrade_Done.getValue());
/* 376 */     mplew.writeInt(mgc.getGuildId());
/* 377 */     mplew.writeInt(mgc.getId());
/* 378 */     mplew.write(mgc.getGuildRank());

/* 380 */     return mplew.getPacket();
   }





   public static byte[] updatePlayerContribution(int guildId, int chrId, int contribution) {
/* 388 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 389 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 391 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 392 */     mplew.write(GuildOpcode.GuildRes_SetMemberCommitment_Done.getValue());
/* 393 */     mplew.writeInt(guildId);
/* 394 */     mplew.writeInt(chrId);
/* 395 */     mplew.writeInt(contribution);
/* 396 */     mplew.writeInt(contribution);
/* 397 */     mplew.writeInt(0);
/* 398 */     mplew.writeLong(PacketHelper.getTime(System.currentTimeMillis()));

/* 400 */     return mplew.getPacket();
   }





   public static byte[] guildEmblemChange(int guildId, short bg, byte bgcolor, short logo, byte logocolor) {
/* 408 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 409 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 411 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 412 */     mplew.write(GuildOpcode.GuildRes_SetMark_Done.getValue());
/* 413 */     mplew.writeInt(guildId);
/* 414 */     mplew.writeShort(bg);
/* 415 */     mplew.write(bgcolor);
/* 416 */     mplew.writeShort(logo);
/* 417 */     mplew.write(logocolor);

/* 419 */     return mplew.getPacket();
   }




   public static byte[] updateGuildInfo(int guildId, int totalContribution, int guildlevel) {
/* 426 */     return updateGuildInfo(guildId, totalContribution, guildlevel, 0);
   }

   public static byte[] updateGuildInfo(int guildId, int totalContribution, int guildlevel, int totalGP) {
/* 430 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 431 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 433 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 434 */     mplew.write(GuildOpcode.GuildRes_IncPoint_Done.getValue());
/* 435 */     mplew.writeInt(guildId);
/* 436 */     mplew.writeInt(totalContribution);
/* 437 */     mplew.writeInt(guildlevel);
/* 438 */     mplew.writeInt(totalGP);

/* 440 */     return mplew.getPacket();
   }





   public static byte[] showGuildRanks(int npcid, List<MapleGuildRanking.GuildRankingInfo> all, boolean show) {
/* 448 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 449 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 451 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 452 */     mplew.write(GuildOpcode.GuildRes_ShowGuildRanking.getValue());
/* 453 */     mplew.writeInt(npcid);
/* 454 */     mplew.writeInt(show ? all.size() : 0);
/* 455 */     if (show) {
/* 456 */       int n2 = 0;
/* 457 */       for (MapleGuildRanking.GuildRankingInfo info : all) {
/* 458 */         mplew.writeShort(++n2);
/* 459 */         mplew.writeMapleAsciiString(info.getName());
/* 460 */         mplew.writeInt(info.getGP());
/* 461 */         mplew.writeInt(info.getLogo());
/* 462 */         mplew.writeInt(info.getLogoColor());
/* 463 */         mplew.writeInt(info.getLogoBg());
/* 464 */         mplew.writeInt(info.getLogoBgColor());
       }
     }

/* 468 */     return mplew.getPacket();
   }





   public static byte[] guildLeaderChanged(int guildId, int oldLeader, int newLeader, int allianceId) {
/* 476 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 477 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 479 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 480 */     mplew.write(GuildOpcode.GuildRes_ChangeMaster_Done.getValue());
/* 481 */     mplew.writeInt(guildId);
/* 482 */     mplew.writeInt(oldLeader);
/* 483 */     mplew.writeInt(newLeader);
/* 484 */     mplew.write((allianceId > 0) ? 1 : 0);
/* 485 */     if (allianceId > 0) {
/* 486 */       mplew.writeInt(allianceId);
     }

/* 489 */     return mplew.getPacket();
   }





   public static byte[] showGuildBeginnerSkill() {
/* 497 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 498 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 500 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 501 */     mplew.write(GuildOpcode.GuildRes_BattleSkillOpen.getValue());
/* 502 */     mplew.writeShort(0);
/* 503 */     mplew.writeShort(0);

/* 505 */     return mplew.getPacket();
   }




   public static byte[] removeGuildFromAlliance(MapleGuildAlliance alliance, MapleGuild expelledGuild, boolean expelled) {
/* 512 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 513 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 515 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 516 */     mplew.write(16);
/* 517 */     addAllianceInfo(mplew, alliance);
/* 518 */     addGuildInfo(mplew, expelledGuild);
/* 519 */     mplew.write(expelled ? 1 : 0);

/* 521 */     return mplew.getPacket();
   }




   public static byte[] changeAlliance(MapleGuildAlliance alliance, boolean in) {
/* 528 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 529 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 531 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 532 */     mplew.write(1);
/* 533 */     mplew.write(in ? 1 : 0);
/* 534 */     mplew.writeInt(in ? alliance.getId() : 0);
/* 535 */     int noGuilds = alliance.getNoGuilds();
/* 536 */     MapleGuild[] g = new MapleGuild[noGuilds]; int i;
/* 537 */     for (i = 0; i < noGuilds; i++) {
/* 538 */       g[i] = WorldGuildService.getInstance().getGuild(alliance.getGuildId(i));
/* 539 */       if (g[i] == null) {
/* 540 */         return MaplePacketCreator.enableActions();
       }
     }
/* 543 */     mplew.write(noGuilds);
/* 544 */     for (i = 0; i < noGuilds; i++) {
/* 545 */       mplew.writeInt(g[i].getId());

/* 547 */       Collection<MapleGuildCharacter> members = g[i].getMembers();
/* 548 */       mplew.writeInt(members.size());
/* 549 */       for (MapleGuildCharacter mgc : members) {
/* 550 */         mplew.writeInt(mgc.getId());
/* 551 */         mplew.write(in ? mgc.getAllianceRank() : 0);
       }
     }

/* 555 */     return mplew.getPacket();
   }




   public static byte[] changeAllianceLeader(int allianceid, int newLeader, int oldLeader) {
/* 562 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 563 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 565 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 566 */     mplew.write(2);
/* 567 */     mplew.writeInt(allianceid);
/* 568 */     mplew.writeInt(oldLeader);
/* 569 */     mplew.writeInt(newLeader);

/* 571 */     return mplew.getPacket();
   }




   public static byte[] updateAllianceLeader(int allianceid, int newLeader, int oldLeader) {
/* 578 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 579 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 581 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 582 */     mplew.write(25);
/* 583 */     mplew.writeInt(allianceid);
/* 584 */     mplew.writeInt(oldLeader);
/* 585 */     mplew.writeInt(newLeader);

/* 587 */     return mplew.getPacket();
   }




   public static byte[] sendAllianceInvite(String allianceName, MapleCharacter inviter) {
/* 594 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 595 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 597 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 598 */     mplew.write(3);
/* 599 */     mplew.writeInt(inviter.getGuildId());
/* 600 */     mplew.writeMapleAsciiString(inviter.getName());
/* 601 */     mplew.writeMapleAsciiString(allianceName);

/* 603 */     return mplew.getPacket();
   }

   public static byte[] changeGuildInAlliance(MapleGuildAlliance alliance, MapleGuild guild, boolean add) {
/* 607 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 608 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 610 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 611 */     mplew.write(4);
/* 612 */     mplew.writeInt(add ? alliance.getId() : 0);
/* 613 */     mplew.writeInt(guild.getId());
/* 614 */     Collection<MapleGuildCharacter> members = guild.getMembers();
/* 615 */     mplew.writeInt(members.size());
/* 616 */     for (MapleGuildCharacter mgc : members) {
/* 617 */       mplew.writeInt(mgc.getId());
/* 618 */       mplew.write(add ? mgc.getAllianceRank() : 0);
     }

/* 621 */     return mplew.getPacket();
   }

   public static byte[] changeAllianceRank(int allianceid, MapleGuildCharacter player) {
/* 625 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 626 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 628 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 629 */     mplew.write(5);
/* 630 */     mplew.writeInt(allianceid);
/* 631 */     mplew.writeInt(player.getId());
/* 632 */     mplew.writeInt(player.getAllianceRank());

/* 634 */     return mplew.getPacket();
   }

   public static byte[] createGuildAlliance(MapleGuildAlliance alliance) {
/* 638 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 639 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 641 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 642 */     mplew.write(15);
/* 643 */     addAllianceInfo(mplew, alliance);
/* 644 */     int noGuilds = alliance.getNoGuilds();
/* 645 */     MapleGuild[] g = new MapleGuild[noGuilds];
/* 646 */     for (int i = 0; i < alliance.getNoGuilds(); i++) {
/* 647 */       g[i] = WorldGuildService.getInstance().getGuild(alliance.getGuildId(i));
/* 648 */       if (g[i] == null) {
/* 649 */         return MaplePacketCreator.enableActions();
       }
     }
/* 652 */     for (MapleGuild gg : g) {
/* 653 */       addGuildInfo(mplew, gg);
     }

/* 656 */     return mplew.getPacket();
   }

   public static byte[] getAllianceInfo(MapleGuildAlliance alliance) {
/* 660 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 661 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 663 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 664 */     mplew.write(12);
/* 665 */     mplew.write((alliance == null) ? 0 : 1);
/* 666 */     if (alliance != null) {
/* 667 */       addAllianceInfo(mplew, alliance);
     }

/* 670 */     return mplew.getPacket();
   }

   public static byte[] getAllianceUpdate(MapleGuildAlliance alliance) {
/* 674 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 675 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 677 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 678 */     mplew.write(23);
/* 679 */     addAllianceInfo(mplew, alliance);

/* 681 */     return mplew.getPacket();
   }

   public static byte[] getGuildAlliance(MapleGuildAlliance alliance) {
/* 685 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 686 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 688 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 689 */     mplew.write(13);
/* 690 */     if (alliance == null) {
/* 691 */       mplew.writeInt(0);
/* 692 */       return mplew.getPacket();
     }
/* 694 */     int noGuilds = alliance.getNoGuilds();
/* 695 */     MapleGuild[] guildlist = new MapleGuild[noGuilds];
/* 696 */     for (int i = 0; i < alliance.getNoGuilds(); i++) {
/* 697 */       guildlist[i] = WorldGuildService.getInstance().getGuild(alliance.getGuildId(i));
/* 698 */       if (guildlist[i] == null) {
/* 699 */         return MaplePacketCreator.enableActions();
       }
     }
/* 702 */     mplew.writeInt(noGuilds);
/* 703 */     for (MapleGuild guild : guildlist) {
/* 704 */       addGuildInfo(mplew, guild);
     }

/* 707 */     return mplew.getPacket();
   }

   public static byte[] addGuildToAlliance(MapleGuildAlliance alliance, MapleGuild newGuild) {
/* 711 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 712 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 714 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 715 */     mplew.write(18);
/* 716 */     addAllianceInfo(mplew, alliance);
/* 717 */     mplew.writeInt(newGuild.getId());
/* 718 */     addGuildInfo(mplew, newGuild);
/* 719 */     mplew.write(0);

/* 721 */     return mplew.getPacket();
   }

   private static void addAllianceInfo(MaplePacketLittleEndianWriter mplew, MapleGuildAlliance alliance) {
/* 725 */     mplew.writeInt(alliance.getId());
/* 726 */     mplew.writeMapleAsciiString(alliance.getName()); int i;
/* 727 */     for (i = 1; i <= 5; i++) {
/* 728 */       mplew.writeMapleAsciiString(alliance.getRank(i));
     }
/* 730 */     mplew.write(alliance.getNoGuilds());
/* 731 */     for (i = 0; i < alliance.getNoGuilds(); i++) {
/* 732 */       mplew.writeInt(alliance.getGuildId(i));
     }
/* 734 */     mplew.writeInt(alliance.getCapacity());
/* 735 */     mplew.writeMapleAsciiString(alliance.getNotice());
   }

   public static byte[] allianceMemberOnline(int alliance, int gid, int id, boolean online) {
/* 739 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 740 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 742 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 743 */     mplew.write(14);
/* 744 */     mplew.writeInt(alliance);
/* 745 */     mplew.writeInt(gid);
/* 746 */     mplew.writeInt(id);
/* 747 */     mplew.write(online ? 1 : 0);

/* 749 */     return mplew.getPacket();
   }

   public static byte[] updateAlliance(MapleGuildCharacter mgc, int allianceid) {
/* 753 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 754 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 756 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 757 */     mplew.write(24);
/* 758 */     mplew.writeInt(allianceid);
/* 759 */     mplew.writeInt(mgc.getGuildId());
/* 760 */     mplew.writeInt(mgc.getId());
/* 761 */     mplew.writeInt(mgc.getLevel());
/* 762 */     mplew.writeInt(mgc.getJobId());

/* 764 */     return mplew.getPacket();
   }

   public static byte[] updateAllianceRank(int allianceid, MapleGuildCharacter mgc) {
/* 768 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 769 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 771 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 772 */     mplew.write(27);
/* 773 */     mplew.writeInt(allianceid);
/* 774 */     mplew.writeInt(mgc.getId());
/* 775 */     mplew.writeInt(mgc.getAllianceRank());

/* 777 */     return mplew.getPacket();
   }




   public static byte[] disbandAlliance(int alliance) {
/* 784 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 785 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 787 */     mplew.writeShort(SendPacketOpcode.ALLIANCE_OPERATION.getValue());
/* 788 */     mplew.write(29);
/* 789 */     mplew.writeInt(alliance);

/* 791 */     return mplew.getPacket();
   }




   public static byte[] BBSThreadList(List<MapleBBSThread> bbs, int start) {
/* 798 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 799 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();




/* 804 */     mplew.writeShort(SendPacketOpcode.BBS_OPERATION.getValue());
/* 805 */     mplew.write(6);

/* 807 */     if (bbs == null) {
/* 808 */       mplew.write(0);
/* 809 */       mplew.writeInt(0);
/* 810 */       return mplew.getPacket();
     }



/* 815 */     MapleBBSThread notice = null;
/* 816 */     for (MapleBBSThread b : bbs) {
/* 817 */       if (b.isNotice()) {
/* 818 */         notice = b;
/* 819 */         bbs.remove(b);
         break;
       }
     }
/* 823 */     mplew.write((notice == null) ? 0 : 1);
/* 824 */     if (notice != null) {
/* 825 */       addThread(mplew, notice);
     }
/* 827 */     int threadCount = bbs.size();
/* 828 */     if (threadCount < start)
     {
/* 830 */       start = 0;
     }

/* 833 */     mplew.writeInt(threadCount);
/* 834 */     int pages = Math.min(10, threadCount - start);
/* 835 */     mplew.writeInt(pages);

/* 837 */     for (int i = 0; i < pages; i++) {
/* 838 */       addThread(mplew, bbs.get(start + i));
     }

/* 841 */     return mplew.getPacket();
   }

   private static void addThread(MaplePacketLittleEndianWriter mplew, MapleBBSThread thread) {
/* 845 */     mplew.writeInt(thread.localthreadID);
/* 846 */     mplew.writeInt(thread.ownerID);
/* 847 */     mplew.writeMapleAsciiString(thread.name);
/* 848 */     mplew.writeLong(PacketHelper.getTime(thread.timestamp));
/* 849 */     mplew.writeInt(thread.icon);
/* 850 */     mplew.writeInt(thread.getReplyCount());
   }

   public static byte[] showThread(MapleBBSThread thread) {
/* 854 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 855 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 857 */     mplew.writeShort(SendPacketOpcode.BBS_OPERATION.getValue());
/* 858 */     mplew.write(7);

/* 860 */     mplew.writeInt(thread.localthreadID);
/* 861 */     mplew.writeInt(thread.ownerID);
/* 862 */     mplew.writeLong(PacketHelper.getTime(thread.timestamp));
/* 863 */     mplew.writeMapleAsciiString(thread.name);
/* 864 */     mplew.writeMapleAsciiString(thread.text);
/* 865 */     mplew.writeInt(thread.icon);
/* 866 */     mplew.writeInt(thread.getReplyCount());
/* 867 */     for (MapleBBSReply reply : thread.replies.values()) {
/* 868 */       mplew.writeInt(reply.replyid);
/* 869 */       mplew.writeInt(reply.ownerID);
/* 870 */       mplew.writeLong(PacketHelper.getTime(reply.timestamp));
/* 871 */       mplew.writeMapleAsciiString(reply.content);
     }

/* 874 */     return mplew.getPacket();
   }

   public static byte[] loadGuildName(MapleCharacter chr) {
/* 878 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 879 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 881 */     mplew.writeShort(SendPacketOpcode.LOAD_GUILD_NAME.getValue());
/* 882 */     mplew.writeInt(chr.getId());
/* 883 */     if (chr.getGuildId() <= 0) {
/* 884 */       mplew.writeShort(0);
     } else {
/* 886 */       MapleGuild guild = WorldGuildService.getInstance().getGuild(chr.getGuildId());
/* 887 */       if (guild != null) {
/* 888 */         mplew.writeMapleAsciiString(guild.getName());
       } else {
/* 890 */         mplew.writeShort(0);
       }
     }
/* 893 */     return mplew.getPacket();
   }

   public static byte[] loadGuildIcon(MapleCharacter chr) {
/* 897 */     log.info("调用"+Thread.currentThread().getStackTrace()[1].getMethodName());
/* 898 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

/* 900 */     mplew.writeShort(SendPacketOpcode.LOAD_GUILD_ICON.getValue());
/* 901 */     mplew.writeInt(chr.getId());
/* 902 */     if (chr.getGuildId() <= 0) {
/* 903 */       mplew.writeZeroBytes(6);
     } else {
/* 905 */       MapleGuild guild = WorldGuildService.getInstance().getGuild(chr.getGuildId());
/* 906 */       if (guild != null) {
/* 907 */         mplew.writeShort(guild.getLogoBG());
/* 908 */         mplew.write(guild.getLogoBGColor());
/* 909 */         mplew.writeShort(guild.getLogo());
/* 910 */         mplew.write(guild.getLogoColor());
       } else {
/* 912 */         mplew.writeZeroBytes(6);
       }
     }
/* 915 */     return mplew.getPacket();
   }

   public static byte[] guildSearch_Results(MapleClient c, List<Pair<Integer, MapleGuild>> guild) {
/* 919 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/* 920 */     mplew.writeShort(SendPacketOpcode.GUILD_SEARCH_RESULTS.getValue());
/* 921 */     mplew.writeInt(guild.size());
/* 922 */     for (Pair<Integer, MapleGuild> Guild : guild) {
/* 923 */       mplew.writeInt(((Integer)Guild.getLeft()).intValue());
/* 924 */       mplew.writeInt(((MapleGuild)Guild.getRight()).getLevel());
/* 925 */       mplew.writeMapleAsciiString(((MapleGuild)Guild.right).getName());
/* 926 */       mplew.writeMapleAsciiString(((MapleGuild)Guild.right).getLeader(c).getName());
/* 927 */       mplew.writeInt(((MapleGuild)Guild.getRight()).getCapacity());
/* 928 */       mplew.writeInt(((MapleGuild)Guild.getRight()).getMembers().size() / ((MapleGuild)Guild.getRight()).getCapacity());
     }
/* 930 */     return mplew.getPacket();
   }


   public static byte[] viewGuildInfo(MapleGuild g) {
/* 935 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();









/* 945 */     mplew.writeShort(SendPacketOpcode.GUILD_OPERATION.getValue());
/* 946 */     mplew.write(49);

/* 948 */     mplew.writeInt(g.getId());
/* 949 */     addGuildInfo(mplew, g);

/* 951 */     return mplew.getPacket();
   }
 }


/* Location:              C:\PGX\Server.jar!\tools\packet\GuildPacket.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */